/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.lcfgly.Dao;

import com.lcfgly.Database.ShopImgs;
import com.lcfgly.DatabaseFactory.DataFactoryInterface;
import com.lcfgly.Interface.GetCacheMark;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 * 图片表操作
 * @author lcfgly
 */
@Repository
public class ImgsImpl implements Serializable{
    
    private final String table="shop_imgs";
    private final String sqlheader="SELECT id,imgurl,userid,updatetime FROM shop_imgs ";
    
    @Autowired
        @Qualifier("databaseshoprice")
    private DataFactoryInterface dataFactory;
    
    /**
     * 更新数据
     * @param arg0
     * @return
     * @throws SQLException 
     */
    public int update(ShopImgs arg0) throws SQLException {
        return dataFactory.update(table,arg0, "id=?", arg0.getId());
    }
    
    /**
     * 批量更新
     * @param args
     * @return
     * @throws SQLException 
     */
    public int[] update(List<ShopImgs> args) throws SQLException {
         int[] result=new int[args.size()];
        int i=0;
        for (ShopImgs menu : args) {
            result[i++]=dataFactory.update(table,menu, "id", menu.getId());
        }
        return result;
    }
    
    /**
     * 按照userID获取图片
     * @param id
     * @return
     * @throws SQLException 
     */
    @GetCacheMark("Imgs_${0}")
    public List findByUserId(int id) throws SQLException{
        String sql=sqlheader+" WHERE userid= ?";
        return dataFactory.rows(ShopImgs.class,sql, id);
    }
    
    /**
     * 添加数据
     * @param arg
     * @return
     * @throws SQLException 
     */
    public int insert(ShopImgs arg)throws SQLException{
        return dataFactory.insert(arg, table);
    }
    
}
